#!/usr/bin/env node

const fs = require('fs');
const src = process.argv[2];
const dst = process.argv[3];

if (!src || !dst) {
  console.error('Usage: node 07-my-cp.js <source> <destination>');
  process.exit(1);
}

try {
  // 读取源文件内容
  const data = fs.readFileSync(src);
  // 获取源文件的权限
  const stats = fs.statSync(src);
  // 写入目标文件，同时设置权限
  fs.writeFileSync(dst, data, { mode: stats.mode });
  console.log(`File copied from ${src} to ${dst}`);
} catch (err) {
  console.error('Error copying file:', err.message);
}